#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main() {
    pid_t pid = fork();

    if (pid == 0) {
        // ✅ 子进程先执行，立即打印并刷新输出
        printf("I am child, Pid is:%d, my_Parent_pid is:%d\n", getpid(), getppid());
        fflush(stdout);
    } else if (pid > 0) {
        // ✅ 父进程等子进程执行完后再 wait 和退出
        wait(NULL);
        printf("I am parent, Pid is:%d, my_Child_pid is:%d\n", getpid(), pid);
        printf("Parent done waiting for child\n");
    } else {
        perror("fork failed");
        return 1;
    }

    return 0;
}

